package ee.serge.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.PushButton;


public class AlertBox extends AbsolutePanel {
   
   private static int RED = 0;
   private static int GREEN = 1;
   private static AlertBox alertBox;
   private HTML label;
   
   public AlertBox() {
      alertBox = this;
      hide();
      setHeight("auto");
      label = new HTML("awd");
      add(label);
      addStyleName("alertbox");
      label.setStyleName("inner");
      
      PushButton closeButton = new PushButton();
      add(closeButton);
      closeButton.setStyleName("close-button");
      closeButton.addClickHandler(new ClickHandler() {
         @Override
         public void onClick(ClickEvent event) {
            hide();
         }
      });
   }
   
   public void setText(String message, int color) {
      label.setHTML(message);
      if (color == RED) {
         setStyleName("redAlertbox");
      } else {
         setStyleName("greenAlertbox");
      }
   }
   
   public static void showSuccess(String message) {
      alertBox.setVisible(true);
      alertBox.setText(message, GREEN);
   }
   
   public static void showError(String message) {
      alertBox.setVisible(true);
      alertBox.setText(message, RED);
   }
   
   public static void hide() {
      alertBox.setVisible(false);
   }
   
}

/*public class AlertBox extends AnimPanel {

   private SimplePanel panel;
   private static AlertBox alertBox;
   
   public AlertBox() {
      alertBox = this;
      setSize("100%", "57px");
      panel = new SimplePanel();
      panel.add(new Label("Toimingud on salvestatud"));
      panel.setStyleName("inner");
      setStyleName("alertbox");
      setWidget(panel);
   }
   
   public void showThis() {
      run(57);
   }
   
   public void hideThis() {
      
   }
   
   public static void show() {
      alertBox.showThis();
   }

}*/
